package Search;

//从今天2022.3.31开始学习查找算法
//这里要引用一下之前的排序算法
public class Binary {

    private Binary(){}

    public static <E extends Comparable<E>> int search(E[] data,E target){
        return search(data,0,data.length - 1,target);
    }

    private static <E extends Comparable<E>> int search(E[] data,int l,int r,E target){
        if (l > r)return -1;
        int mid = l + (r - l) / 2;

        if (data[mid].compareTo(target) == 0)
            return mid;

        if (data[mid].compareTo(target) < 0)
            return search(data,mid + 1,r,target);

        return search(data,l,mid - 1,target);
    }
}
